<template>
  <div>
    <el-form>
      <div class="search-panel">
        <el-row>
          <el-col :span="6"
            ><div class="grid-content bg-purple-dark">
              <el-form-item label="项目名称" label-width="80px">
                <el-select
                  v-model="ProjectName"
                  size="mini"
                  placeholder="请选择"
                  @change="ProChange"
                  style="width: 90%"
                >
                  <el-option-group
                    v-for="group in optionProJect"
                    :key="group.lable"
                    :label="group.lable"
                  >
                    <el-option
                      v-for="item in group.options"
                      :key="item.value"
                      :label="item.lable"
                      :value="item.value"
                    />
                  </el-option-group>
                </el-select>
              </el-form-item></div
          ></el-col>
          <el-col :span="6"
            ><div class="grid-content bg-purple-dark">
              <el-form-item label="项目版本">
                <el-select
                  v-model="ProVersion"
                  size="mini"
                  placeholder="请选择"
                  @change="VersionChange"
                  value-key="版本号"
                  style="width: 70%"
                >
                  <el-option
                    v-for="item in optionVersion"
                    :key="item.版本号"
                    :label="item.版本号"
                    :value="item"
                  />
                </el-select>
              </el-form-item></div
          ></el-col>
          <el-col :span="2">
            <div
              style="
                width: 110px;
                height: 30px;
                line-height: 36px;
                font-weight: bold;
              "
            >
              <span
                v-show="ProState != '' && ProState != undefined"
                :style="{ 'font-size': '14px', color: funColor(ProState) }"
                >{{ funState(ProState) }}</span
              >
            </div>
          </el-col>
          <el-col :span="10" style="text-align: right">
            <el-button
              size="mini"
              @click="dialogVisibleupdate = true"
              v-if="ProState == '2' && DeptName == '项目部'"
              ><img
                src="../../assets/image/审批通过.png"
                style="width: 9px; margin-right: 5px"
              />修改</el-button
            >
            <el-button
              size="mini"
              @click="ProApproval"
              v-if="ProState == '1' && DeptName == '生产管理部'"
              ><img
                src="../../assets/image/审批通过.png"
                style="width: 9px; margin-right: 5px"
              />批准</el-button
            >
            <el-button
              size="mini"
              @click="ProRebut"
              v-if="ProState == '1' && DeptName == '生产管理部'"
              ><img
                src="../../assets/image/驳回.png"
                style="width: 9px; margin-right: 5px"
              />驳回</el-button
            >
            <el-button size="mini" @click="Audit" v-if="DeptName == '项目部'"
              ><img
                src="../../assets/image/提交审批.png"
                style="width: 9px; margin-right: 5px"
              />提交审批</el-button
            >
            <el-button
              size="mini"
              @click="OpendialogVisibleImport"
              v-if="DeptName == '项目部'"
              ><img
                src="../../assets/image/导入.png"
                style="width: 9px; margin-right: 5px"
              />导入</el-button
            >
            <el-button size="mini" @click="opendialogVisiblefile()"
              >附件下载</el-button
            >
          </el-col>
        </el-row>
      </div>
    </el-form>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="全部" name="first">
        <div>
          <el-table
            :data="Datalist"
            style="width: 100%; margin-bottom: 20px"
            row-key="objectID"
            border
            :row-style="{ height: '20px' }"
            :cell-style="{ padding: '0px' }"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
            @cell-mouse-enter="enter"
            @cell-mouse-leave="leave"
            v-loading="loading"
            :element-loading-text="loadtext"
            default-expand-all
          >
            <el-table-column
              prop="任务编码"
              fixed
              label="任务编码"
              width="200"
            />
            <el-table-column
              label="作业名称"
              show-overflow-tooltip
              fixed
              width="210"
            >
              <template scope="scope">
                <span
                  style="
                    width: 160px;
                    height: 17px;
                    display: inline-block;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                  "
                  >{{ scope.row.任务名称 }}</span
                ><img
                  v-show="
                    scope.row.是否关键节点 == 1 &&
                    scope.row.children.length == 0
                  "
                  style="
                    width: 10px;
                    float: right;
                    margin-right: 10px;
                    margin-top: 6px;
                  "
                  src="../../assets/image/关键路径_ed.png" /></template
            ></el-table-column>
            <el-table-column prop="设计量" label="设计量" width="80" />
            <el-table-column label="进度" width="200">
              <template scope="scope">
                <el-progress
                  :percentage="scope.row.jind"
                  :color="customColorMethod"
                />
              </template>
            </el-table-column>
            <el-table-column label="状态" width="140">
              <template scope="scope">
                <div v-if="scope.row.zhuangt == 1" style="text-align: center">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    :content="
                      '任务“' +
                      scope.row.任务名称 +
                      '”计划于' +
                      scope.row.完成时间 +
                      '完成,此为关键路径任务，予以重视'
                    "
                    placement="top-start"
                  >
                    <img
                      style="cursor: pointer; margin: 0px 15px -6px 0px"
                      src="../../assets/image/预警.png"
                    />
                  </el-tooltip>
                  <el-tag>正常</el-tag>
                </div>
                <div v-else style="text-align: center">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    :content="
                      '任务“' +
                      scope.row.任务名称 +
                      '”计划于' +
                      scope.row.完成时间 +
                      '完成,现已超期，予以重视'
                    "
                    placement="top-start"
                  >
                    <img
                      style="cursor: pointer; margin: 0px 15px -6px 0px"
                      src="../../assets/image/预期.png"
                    />
                  </el-tooltip>
                  <el-tag type="danger">滞后</el-tag>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="开始时间" label="计划开始时间" width="140" />
            <el-table-column prop="完成时间" label="计划完成时间" width="140" />
            <el-table-column
              prop="累计完成总量"
              label="累计完成总量"
              width="100"
            />
            <el-table-column prop="年度完成量" label="年度完成量" width="100" />
            <el-table-column prop="月度完成量" label="月度完成量" width="100" />
            <el-table-column fixed="right" label="操作" width="180">
              <template scope="scope">
                <el-button
                  v-if="
                    (ProState == '0' || ProState == '3') &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  icon="el-icon-circle-plus-outline"
                  style="color: gray"
                  size="small"
                  @click="add(scope.row)"
                  >新增</el-button
                >
                <el-button
                  v-if="
                    (ProState == '0' || ProState == '3') &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  icon="el-icon-edit"
                  style="color: gray"
                  size="small"
                  @click="edit(scope.row)"
                  >编辑</el-button
                >
                <el-button
                  v-if="
                    (ProState == '0' || ProState == '3') &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  icon="el-icon-delete"
                  style="color: gray"
                  size="small"
                  @click="ProDelNode(scope.row.任务编码)"
                  >删除</el-button
                >
                <el-button
                  v-if="
                    scope.row.是否关键节点 == 1 &&
                    ProState == '2' &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  size="small"
                  style="color: gray"
                  @click="CancelKeyNodesOfProject(scope, 1)"
                  ><img
                    src="../../assets/image/关键路径_ed.png"
                    style="width: 10px; margin-right: 5px"
                  />已设为关键路径</el-button
                >
                <el-button
                  v-if="
                    scope.row.是否关键节点 != 1 &&
                    ProState == '2' &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  size="small"
                  style="color: gray"
                  @click="SetKeyNodesOfProject(scope)"
                  ><img
                    src="../../assets/image/关键路径_un.png"
                    style="width: 10px; margin-right: 5px"
                  />设为关键路径</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-tab-pane>
      <el-tab-pane name="second">
        <span slot="label"
          ><img
            src="../../assets/image/关键路径.png"
            style="width: 10px; margin-right: 3px"
          />关键路径</span
        >
        <div>
          <el-table
            :data="Datalist"
            style="width: 100%; margin-bottom: 20px"
            row-key="objectID"
            border
            :row-style="{ height: '20px' }"
            :cell-style="{ padding: '0px' }"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
            @cell-mouse-enter="enter"
            @cell-mouse-leave="leave"
            v-loading="loading"
            :element-loading-text="loadtext"
            default-expand-all
          >
            <el-table-column
              prop="任务编码"
              fixed
              label="任务编码"
              width="200"
            />
            <el-table-column
              label="作业名称"
              show-overflow-tooltip
              fixed
              width="210"
            >
              <template scope="scope">
                <span
                  style="
                    width: 160px;
                    height: 17px;
                    display: inline-block;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                  "
                  >{{ scope.row.任务名称 }}</span
                ><img
                  v-show="
                    scope.row.是否关键节点 == 1 &&
                    scope.row.children.length == 0
                  "
                  style="
                    width: 10px;
                    float: right;
                    margin-right: 10px;
                    margin-top: 6px;
                  "
                  src="../../assets/image/关键路径_ed.png" /></template
            ></el-table-column>
            <el-table-column prop="设计量" label="设计量" width="80" />
            <el-table-column label="进度" width="200">
              <template scope="scope">
                <el-progress
                  :percentage="scope.row.jind"
                  :color="customColorMethod"
                />
              </template>
            </el-table-column>
            <el-table-column label="状态" width="140">
              <template scope="scope">
                <div v-if="scope.row.zhuangt == 1" style="text-align: center">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    :content="
                      '任务“' +
                      scope.row.任务名称 +
                      '”计划于' +
                      scope.row.完成时间 +
                      '完成,此为关键路径任务，予以重视'
                    "
                    placement="top-start"
                  >
                    <img
                      style="cursor: pointer; margin: 0px 15px -6px 0px"
                      src="../../assets/image/预警.png"
                    />
                  </el-tooltip>
                  <el-tag>正常</el-tag>
                </div>
                <div v-else style="text-align: center">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    :content="
                      '任务“' +
                      scope.row.任务名称 +
                      '”计划于' +
                      scope.row.完成时间 +
                      '完成,现已超期，予以重视'
                    "
                    placement="top-start"
                  >
                    <img
                      style="cursor: pointer; margin: 0px 15px -6px 0px"
                      src="../../assets/image/预期.png"
                    />
                  </el-tooltip>
                  <el-tag type="danger">滞后</el-tag>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="开始时间" label="计划开始时间" width="140" />
            <el-table-column prop="完成时间" label="计划完成时间" width="140" />
            <el-table-column
              prop="累计完成总量"
              label="累计完成总量"
              width="100"
            />
            <el-table-column prop="年度完成量" label="年度完成量" width="100" />
            <el-table-column prop="月度完成量" label="月度完成量" width="100" />
            <el-table-column fixed="right" label="操作" width="180">
              <template scope="scope">
                <el-button
                  v-if="
                    (ProState == '0' || ProState == '3') &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  icon="el-icon-circle-plus-outline"
                  style="color: gray"
                  size="small"
                  @click="add(scope.row)"
                  >新增</el-button
                >
                <el-button
                  v-if="
                    (ProState == '0' || ProState == '3') &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  icon="el-icon-edit"
                  style="color: gray"
                  size="small"
                  @click="edit(scope.row)"
                  >编辑</el-button
                >
                <el-button
                  v-if="
                    (ProState == '0' || ProState == '3') &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  icon="el-icon-delete"
                  style="color: gray"
                  size="small"
                  @click="ProDelNode(scope.row.任务编码)"
                  >删除</el-button
                >
                <el-button
                  v-if="
                    scope.row.是否关键节点 == 1 &&
                    ProState == '2' &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  size="small"
                  style="color: gray"
                  @click="CancelKeyNodesOfProject(scope, 2)"
                  ><img
                    src="../../assets/image/关键路径_ed.png"
                    style="width: 10px; margin-right: 5px"
                  />已设为关键路径</el-button
                >
                <el-button
                  v-if="
                    scope.row.是否关键节点 != 1 &&
                    ProState == '2' &&
                    scope.row.children.length == 0
                  "
                  type="text"
                  size="small"
                  style="color: gray"
                  @click="SetKeyNodesOfProject(scope)"
                  ><img
                    src="../../assets/image/关键路径_un.png"
                    style="width: 10px; margin-right: 5px"
                  />设为关键路径</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-tab-pane>
    </el-tabs>
    <el-dialog
      title="任务导入"
      :visible.sync="dialogVisibleImport"
      :close-on-click-modal="false"
      width="500px"
    >
      <el-form v-loading="importloading">
        <el-row>
          <el-form-item label="版本号" label-width="90px">
            <el-input
              v-model="versionCode"
              placeholder="请输入版本号"
              size="mini"
            />
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="任务文件" label-width="90px">
            <el-upload
              class="upload-demo"
              action=""
              :on-change="handleChange"
              :on-remove="handleRemove"
              :on-exceed="handleExceed"
              :limit="limitUpload"
              ref="upload"
              accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
              :auto-upload="false"
            >
              <el-button size="small" slot="trigger" type="primary"
                >选择文件</el-button
              >
              <div slot="tip" class="el-upload__tip">
                只 能 上 传 xlsx / xls 文 件
              </div>
              <!-- <div slot="tip" class="el-upload__tip"><el-link type="primary" @click.native="filerightDown()">模板下载</el-link> </div> -->
            </el-upload>
          </el-form-item>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitUpload">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="填写版本号"
      :visible.sync="dialogVisibleupdate"
      :close-on-click-modal="false"
      width="500px"
    >
      <el-form>
        <el-row>
          <el-form-item label="版本号" label-width="90px">
            <el-input
              v-model="updateVersionName"
              placeholder="请输入版本号"
              size="mini"
            />
          </el-form-item>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="UpdateVersionSave">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="附件下载"
      v-loading="fileloading"
      :visible.sync="dialogVisiblefile"
      :close-on-click-modal="false"
      width="550px"
    >
      <el-table
        ref="multipleTable"
        @selection-change="handleSelectionChange"
        :data="FiletableData"
        style="width: 100%"
        height="300px"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="附件名" label="附件名" width="190" />
        <el-table-column prop="上传人" label="上传人" width="100" />
        <el-table-column prop="上传时间" label="上传时间" />
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="download">下 载</el-button>
      </span>
    </el-dialog>

    <el-dialog
      :title="viewtype + '行数据'"
      :visible.sync="dialogVisibleadd"
      :close-on-click-modal="false"
      width="500px"
    >
      <div class="addForm">
        <el-form ref="addForm" :model="addForm" :rules="rules">
          <el-row v-if="viewtype == '新增'">
            <el-form-item label="任务类型" label-width="85px">
              <el-radio-group v-model="addForm.resource">
                <el-radio label="同级数据" />
                <el-radio label="下一级数据" />
              </el-radio-group>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col :span="12"
              ><el-form-item label="任务编码" label-width="85px" prop="code">
                <el-input
                  v-model="addForm.code"
                  placeholder="请输入作业编码"
                  size="mini"
                  style="width: 180px"
                  :disabled="viewtype == '编辑'"
                /> </el-form-item
            ></el-col>
            <el-col :span="12"
              ><el-form-item label="作业名称" label-width="85px" prop="name">
                <el-input
                  v-model="addForm.name"
                  placeholder="请输入作业名称"
                  size="mini"
                  style="width: 180px"
                /> </el-form-item
            ></el-col>
          </el-row>
          <el-row>
            <el-col :span="12"
              ><el-form-item
                label="计划开始时间"
                label-width="110px"
                prop="starttime"
              >
                <el-date-picker
                  v-model="addForm.starttime"
                  type="date"
                  size="mini"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  :picker-options="pickerOptionsStart"
                  style="width: 180px"
                /> </el-form-item
            ></el-col>
            <el-col :span="12"
              ><el-form-item
                label="计划结束时间"
                label-width="110px"
                prop="endtime"
              >
                <el-date-picker
                  v-model="addForm.endtime"
                  size="mini"
                  type="date"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  :picker-options="pickerOptionsEnd"
                  style="width: 180px"
                /> </el-form-item
            ></el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="viewtype == '新增'" @click="ProAdd(0)"
          >继续创建下一个</el-button
        >
        <el-button type="primary" @click="ProAdd(1)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import axios from "axios";
import Global from "@/utils/Global";
import { getApi } from "@/utils/utils.js";
export default {
  data() {
    return {
      apiUrl: "",
      UserID: this.$getUserInfo().ObjectID,
      // DeptName:this.$getUserInfo().ParentName,
      //UserID: "18f923a7-5a5e-426d-94ae-a55ad1a4b239",
      DeptName: "",
      activeName: "first",
      // 表数据
      Datalist: [],
      ProjectName: "",
      ProVersion: [],
      optionProJect: [],
      optionVersion: [],
      FiletableData: [
        {
          id: 1,
          Name: "测试.pdf",
          remark: "张三于2020-01-01上传",
        },
        {
          id: 1,
          Name: "测试.pdf",
          remark: "张三于2020-01-01上传",
        },
      ],
      dialogVisibleImport: false,
      dialogVisible: false,
      dialogVisiblefile: false,
      dialogVisibleadd: false,
      importloading: false,
      loading: false,
      viewtype: "新增",
      addForm: {
        resource: "同级数据",
        starttime: "",
        endtime: "",
        code: "",
        name: "",
        nodeWorkload: "0",
      },
      rules: {
        name: [{ required: true, message: "请输入作业名称", trigger: "blur" }],
        code: [{ required: true, message: "请输入任务编码", trigger: "blur" }],
        starttime: [
          { required: true, message: "请输入开始时间", trigger: "change" },
        ],
        endtime: [
          { required: true, message: "请输入结束时间", trigger: "change" },
        ],
      },
      parentNodeCode: "",
      versionForm: {
        versionName: "",
        file: "",
      },
      pickerOptionsStart: {
        disabledDate: (time) => {
          if (this.addForm.endtime) {
            return time.getTime() > new Date(this.addForm.endtime).getTime();
          }
        },
      },
      pickerOptionsEnd: {
        disabledDate: (time) => {
          if (this.addForm.starttime) {
            return (
              time.getTime() <
              new Date(this.addForm.starttime).getTime() -
                1 * 24 * 60 * 60 * 1000
            );
          }
        },
      },
      limitUpload: 1,
      fileTemp: null,
      tabType: "first",
      versionCode: "",
      fileList: [],
      file: null,
      loadtext: "",
      ProState: "",
      rowData: Object,
      dialogVisibleupdate: false,
      updateVersionName: "",
      fileloading: false,
      multipleSelection: [],
    };
  },
  computed: {},
  created() {
    getApi(this).then((res) => {
      this.apiUrl = res.ApiUrl;
      this.GetProName();
      this.getUserRoot();
    });
  },
  mounted() {},
  methods: {
    customColorMethod(percentage) {
      if (percentage < 50) {
        return "#409eff";
      } else {
        return "#67c23a";
      }
    },
    funState(val) {
      switch (val) {
        case "0":
          return "已上传";
        case "1":
          return "待审批";
        case "2":
          return "已批准";
        case "3":
          return "已驳回";
        default:
          return "";
      }
    },
    funColor(val) {
      switch (val) {
        case "0":
          return "#0078d7";
        case "1":
          return "#ffaa00";
        case "2":
          return "#67c23a";
        case "3":
          return "#ff0000";
        default:
          return "";
      }
    },
    loadText() {
      if (
        this.ProjectName == "" ||
        this.ProjectName == undefined ||
        this.ProjectName == "请选择"
      ) {
        this.loadtext = "请选择项目名称和项目版本";
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getUserRoot() {
      const _that = this;
      axios({
        method: "get",
        url: `${this.apiUrl}/Pmsapi/PlanManagement/GetRoleByLoginUserId?loginUserId=${_that.UserID}`,
      }).then((res) => {
        console.log(res.data.data.role);
        if (res.data.data.role == 1) {
          _that.DeptName = "生产管理部";
        } else if (res.data.data.role == 2) {
          _that.DeptName = "项目部";
        }
      });
    },
    // 绑定项目名称下拉框
    GetProName() {
      const _that = this;
      axios({
        method: "get",
        url: `${this.apiUrl}/Pmsapi/PlanManagement/GetProjectInfoByLoginUserId?loginUserId=${_that.UserID}`,
      }).then((res) => {
        _that.optionProJect.push({
          options: [{ value: "0", lable: "请选择" }],
        });
        if (res.data.data.errMsg == "") {
          res.data.data.data.forEach((element) => {
            _that.optionProJect.push(element);
          });
        }
        this.ProjectName = "0";
      });
    },

    // 绑定项目版本
    GetProversion(xid, val) {
      const _that = this;
      _that.optionVersion = [];
      axios({
        method: "get",
        url: `${this.apiUrl}/Pmsapi/PlanManagement/GetProjectPlanEditions?projectId=${xid}`,
      }).then((res) => {
        _that.optionVersion.push({ 版本号: "请选择" });
        if (res.data.data.errMsg == "") {
          res.data.data.data.forEach((element) => {
            _that.optionVersion.push(element);
          });
        }
        if (val != null && val != undefined)
          _that.ProVersion = _that.optionVersion.find((item) => {
            return item.版本号 == val;
          });
        _that.ProState = _that.ProVersion.状态;
        console.log(_that.ProState);
      });
    },
    // 项目名称改变事件
    ProChange(val) {
      this.Datalist = [];
      this.GetProversion(val, "请选择");
    },
    // 项目版本改变事件
    VersionChange(val) {
      console.log(val);
      this.ProState = val.状态;
      this.$nextTick(() => this.GetList());
    },

    // 选项卡切换事件
    handleClick(tab) {
      const Result = this.CheckSelect();
      if (Result != "") {
        return;
      }
      this.tabType = tab.name;
      this.$nextTick(() => this.GetList());
    },
    //验证下拉框
    CheckSelect() {
      if (
        this.ProjectName == "" ||
        this.ProjectName == undefined ||
        this.ProjectName == "0"
      ) {
        return "请选择项目名称";
      }
      if (
        this.ProVersion.版本号 == "" ||
        this.ProVersion.版本号 == undefined ||
        this.ProVersion.版本号 == "请选择"
      ) {
        return "请选择项目版本";
      }
      return "";
    },
    // 获取项目
    GetList() {
      const _that = this;
      _that.loading = true;
      _that.Datalist = [];
      console.log(this.tabType);
      if (this.tabType == "first") {
        axios({
          method: "get",
          url: `${this.apiUrl}/Pmsapi/PlanManagement/GetProjectPlan?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}`,
        }).then((res) => {
          if (res.data.data.errMsg == "") {
            _that.Datalist = res.data.data.data;
          }
          this.loading = false;
        });
      } else {
        axios({
          method: "get",
          url: `${this.apiUrl}/Pmsapi/PlanManagement/GetKeyNodesOfProject?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}`,
        }).then((res) => {
          if (res.data.data.errMsg == "") {
            _that.Datalist = res.data.data.data;
          }
          this.loading = false;
        });
      }
    },
    // 批准项目计划
    ProApproval() {
      const _that = this;
      const Result = _that.CheckSelect();
      if (Result != "") {
        _that.$message.error(Result);
        return;
      }

      if (_that.ProState == "2") {
        _that.$message.warning("该项目已批准，请勿重复操作！");
        return;
      }
      _that
        .$confirm("是否批准项目执行?", "提示", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        })
        .then(() => {
          _that.loading = true;
          axios({
            method: "get",
            url: `${this.apiUrl}/Pmsapi/PlanManagement/RatifyProjectPlan?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}&createUserId=${_that.UserID}`,
          }).then((res) => {
            if (res.data.data.errMsg == "") {
              _that.$message.success("批准成功");
              // 后面考虑刷新
              this.loading = false;
              _that.GetProversion(_that.ProjectName, _that.ProVersion.版本号);
            } else {
              _that.$message.error("批准失败");
              _that.loading = false;
            }
          });
        })
        .catch(() => {
          _that.$message({
            type: "info",
            message: "已取消批准",
          });
        });
    },
    // 驳回
    ProRebut() {
      const _that = this;
      const Result = _that.CheckSelect();
      if (Result != "") {
        _that.$message.error(Result);
        return;
      }

      if (_that.ProState == "3") {
        _that.$message.warning("该项目已驳回，请勿重复驳回！");
        return;
      }
      _that
        .$confirm("是否驳回项目?", "提示", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        })
        .then(() => {
          _that.loading = true;
          axios({
            method: "get",
            url: `${this.apiUrl}/Pmsapi/PlanManagement/RejectProjectPlan?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}&createUserId=${_that.UserID}`,
          }).then((res) => {
            if (res.data.data.errMsg == "") {
              _that.$message.success("驳回成功");
              // 后面考虑刷新
              _that.GetProversion(_that.ProjectName, _that.ProVersion.版本号);
              this.loading = false;
            } else {
              _that.$message.error("驳回失败");
            }
          });
        })
        .catch(() => {
          _that.$message({
            type: "info",
            message: "已取消驳回",
          });
        });
    },
    //提交审核
    Audit() {
      const _that = this;
      const Result = _that.CheckSelect();
      if (Result != "") {
        _that.$message.error(Result);
        return;
      }
      if (_that.ProState == "1") {
        _that.$message.warning("该项目已提交审核，请勿重复提交！");
        return;
      }
      if (_that.ProState == "2") {
        _that.$message.warning("该项目已审核通过，请勿重复提交！");
        return;
      }
      _that
        .$confirm("是否将项目提交审核?", "提示", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        })
        .then(() => {
          _that.loading = true;
          axios({
            method: "get",
            url: `${this.apiUrl}/Pmsapi/PlanManagement/SubmitPlanForChecked?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}&createUserId=${_that.UserID}`,
          }).then((res) => {
            if (res.data.data.errMsg == "") {
              _that.$message.success("提交成功");
              // 后面考虑刷新
              _that.GetProversion(_that.ProjectName, _that.ProVersion.版本号);
              this.loading = false;
            } else {
              _that.$message.error("提交失败");
              _that.loading = false;
            }
          });
        })
        .catch(() => {
          _that.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    // 删除任务节点
    ProDelNode(id) {
      const _that = this;
      _that
        .$confirm("是否删除该任务?", "提示", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        })
        .then(() => {
          _that.loading = true;
          axios({
            method: "get",
            url: `${this.apiUrl}/Pmsapi/PlanManagement/DeleteProjectPlanNode?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}&nodeCode=${id}`,
          }).then((res) => {
            if (res.data.data.errMsg == "") {
              _that.$message.success("删除成功");
              // 后面考虑刷新
              _that.$nextTick(() => _that.GetList());
            } else {
              _that.$message.error("删除失败");
              _that.loading = false;
            }
          });
        })
        .catch(() => {
          _that.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 设置关键路径
    SetKeyNodesOfProject(item) {
      const _that = this;
      _that.rowData = item;
      _that
        .$confirm("是否设置关键路径?", "提示", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        })
        .then(() => {
          axios({
            method: "get",
            url: `${this.apiUrl}/Pmsapi/PlanManagement/SetKeyNodesOfProject?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}&nodeCode=${item.row.任务编码}`,
          }).then((res) => {
            if (res.data.msg == "success") {
              _that.$message.success("设置成功");
              // 后面考虑刷新
              // _that.$nextTick(() => _that.GetList());
              _that.rowData.row.是否关键节点 = 1;
            } else {
              _that.$message.error("设置失败");
            }
          });
        })
        .catch(() => {
          _that.$message({
            type: "info",
            message: "已取消设置",
          });
        });
    },
    // 取消设置关键路径
    CancelKeyNodesOfProject(item, val) {
      const _that = this;
      _that.rowData = item;
      _that
        .$confirm("是否取消关键路径?", "提示", {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        })
        .then(() => {
          if (val == 2) {
            _that.loading = true;
          }
          axios({
            method: "get",
            url: `${this.apiUrl}/Pmsapi/PlanManagement/CancelKeyNodesOfProject?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}&nodeCode=${item.row.任务编码}&parentNodeCode=${item.row.父级编码}`,
          }).then((res) => {
            if (res.data.msg == "success") {
              _that.$message.success("取消成功");
              // 后面考虑刷新
              if (val == 1) {
                _that.rowData.row.是否关键节点 = 0;
              } else {
                _that.loading = false;
                _that.$nextTick(() => _that.GetList());
              }
            } else {
              _that.$message.error("取消失败");
              _that.loading = false;
            }
          });
        })
        .catch(() => {
          _that.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },
    UpdateVersionSave() {
      let _that = this;
      _that.loading = true;
      axios({
        method: "get",
        url: `${this.apiUrl}/Pmsapi/PlanManagement/CreatePlanByPassedPlan?projectId=${_that.ProjectName}&newPlanEditionCode=${_that.updateVersionName}&loginUserId=${_that.UserID}`,
      }).then((res) => {
        if (res.data.data.errMsg == "") {
          _that.$message.success("修改成功");
          // 后面考虑刷新
          _that.GetProversion(_that.ProjectName, _that.updateVersionName);
          _that.Datalist = res.data.data.data;
          _that.loading = false;
          _that.dialogVisibleupdate = false;
        } else {
          _that.$message.error("新增失败");
          _that.loading = false;
        }
      });
    },
    // 新增/编辑  任务
    ProAdd(type) {
      const _that = this;
      let parentNode = "";
      if (_that.addForm.resource == "同级数据") {
        parentNode = "";
      } else {
        parentNode = _that.parentNodeCode;
      }
      _that.$refs["addForm"].validate((valid) => {
        if (valid) {
          _that.loading = true;
          if (_that.viewtype == "新增") {
            axios({
              method: "get",
              url: `${this.apiUrl}/Pmsapi/PlanManagement/AddProjectPlanNode?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}&nodeCode=${_that.addForm.code}&parentNodeCode=${parentNode}&nodeName=${_that.addForm.name}&nodeWorkload=${_that.addForm.nodeWorkload}&startTime=${_that.addForm.starttime}&endTime=${_that.addForm.endtime}&createUserId=${_that.UserID}`,
            }).then((res) => {
              if (res.data.data.errMsg == "") {
                _that.$message.success("新增成功");
                // 后面考虑刷新
                _that.$nextTick(() => _that.GetList());
                if (type == 1) {
                  _that.dialogVisibleadd = false;
                }
              } else {
                _that.$message.error(res.data.data.errMsg);
                _that.loading = false;
              }
            });
          } else {
            axios({
              method: "get",
              url: `${this.apiUrl}/Pmsapi/PlanManagement/EditProjectPlanNode?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.ProVersion.版本号}&nodeCode=${_that.addForm.code}&parentNodeCode=${_that.parentNodeCode}&nodeName=${_that.addForm.name}&nodeWorkload=${_that.addForm.nodeWorkload}&startTime=${_that.addForm.starttime}&endTime=${_that.addForm.endtime}&createUserId=${_that.UserID}`,
            }).then((res) => {
              if (res.data.data.errMsg == "") {
                _that.dialogVisibleadd = false;
                _that.$message.success("修改成功");
                _that.$nextTick(() => _that.GetList());
                // 后面考虑刷新
              } else {
                _that.$message.error("修改失败");
                _that.loading = false;
              }
            });
          }
        }
      });
    },
    OpendialogVisibleImport() {
      if (
        this.ProjectName == "" ||
        this.ProjectName == undefined ||
        this.ProjectName == "0"
      ) {
        this.$message.error("请选择项目名称");
        return;
      }

      this.dialogVisibleImport = true;
      this.versionCode = "";
      this.fileTemp = null;
      // if(this.$refs.upload!)
      if (this.$refs.upload != undefined) this.$refs.upload.clearFiles();
    },
    handleChange(file, fileList) {
      this.fileTemp = file.raw;
      this.fileList = fileList;
      this.file = file;
      if (this.fileTemp) {
        if (
          this.fileTemp.type ==
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
          this.fileTemp.type == "application/vnd.ms-excel"
        ) {
          //this.importfxx(this.fileTemp)
        } else {
          this.$message({
            type: "warning",
            message: "附件格式错误，请删除后重新上传！",
          });
        }
      } else {
        this.$message({
          type: "warning",
          message: "请上传附件！",
        });
      }
    },
    handleExceed() {
      this.$message({
        type: "warning",
        message: "超出最大上传文件数量的限制！",
      });
      return;
    },
    handleRemove(file, fileList) {
      this.fileList = fileList;
      this.fileTemp = null;
      this.file = file;
    },
    importfxx(obj) {
      let _that = this;
      _that.file = obj;
      var formData = new FormData();
      formData.append("excelPlan", _that.file);
      formData.append("createUserId ", _that.UserID);
      formData.append("projectId", _that.ProjectName);
      formData.append("projectPlanEditionCode", _that.ProVersion.版本号);
      axios({
        method: "post",
        baseURL: `${this.apiUrl}/Pmsapi/PlanManagement/ImportProjectPlan?projectId=${_that.ProjectName}&projectPlanEditionCode=${_that.versionCode}&createUserId=${_that.UserID}`,
        data: formData,
        headers: {
          "Access-Control-Allow-Origin": "*",
          "Content-type": "multipart/form-data",
        },
        processData: false,
      }).then(function (res) {
        _that.loading = false;
        if (res.data.code == 200) {
          _that.$message.success("导入成功");
          //后面考虑刷新
          _that.GetProversion(_that.ProjectName, _that.versionCode);
          _that.Datalist = res.data.data.data;
          _that.dialogVisibleImport = false;
        } else {
          _that.$message.error("导入失败");
          console.log(res.data);
          _that.loading = false;
        }
      });
    },
    //手动上传
    submitUpload() {
      this.loading = true;
      this.importfxx(this.fileTemp);
    },
    //绑定文件列表
    opendialogVisiblefile() {
      const _that = this;
      if (
        _that.ProjectName == "" ||
        _that.ProjectName == undefined ||
        _that.ProjectName == "请选择" ||
        _that.ProjectName == "0"
      ) {
        _that.$message.error("请选择项目名称");
        return;
      }
      this.dialogVisiblefile = true;
      _that.fileloading = true;
      axios({
        method: "get",
        url: `${this.apiUrl}/Pmsapi/PlanManagement/GetDownloadList?projectId=${_that.ProjectName}`,
      }).then((res) => {
        if (res.data.data.errMsg == "") {
          _that.FiletableData = res.data.data.data;
          _that.fileloading = false;
        } else {
          _that.fileloading = false;
        }
      });
    },
    download() {
      let _that = this;
      if (_that.multipleSelection.length == 0) {
        _that.message.error("请选择要下载的文件！");
        return;
      }
      let arrid = [];
      _that.multipleSelection.forEach((element) => {
        arrid.push(element.objectID);
      });
      // 调下载接口
      axios({
        method: "get",
        url: `${
          this.apiUrl
        }/Pmsapi/PlanManagement/GetDownloadAddress?projectId=${
          _that.ProjectName
        }&strPlanEditionItems=${arrid.join(",")}`,
      }).then((res) => {
        debugger;
        window.open(res.data.data.downloadUrl);
        this.dialogVisiblefile = false;
      });
    },
    VersionSave() {
      this.dialogVisible = false;
      // 调保存接口
    },
    add(item) {
      this.dialogVisibleadd = true;
      this.viewtype = "新增";
      this.parentNodeCode = item.任务编码;
      if (this.$refs["addForm"] != undefined)
        this.$refs["addForm"].resetFields();
    },
    edit(item) {
      this.dialogVisibleadd = true;
      this.viewtype = "编辑";
      this.addForm.code = item.任务编码;
      this.addForm.name = item.任务名称;
      this.addForm.starttime = item.开始时间;
      this.addForm.endtime = item.完成时间;
    },
    enter(row, column, cell) {
      // console.log(row);
      // console.log(column);
      // console.log(cell);
    },
    leave(row, column, cell) {},
  },
};
</script>

<style scoped>
/deep/ * {
  font-size: 12px;
}
.search-panel {
  padding: 20px 5px 0px 0px;
  box-sizing: border-box;
}
.manage-panel {
  box-sizing: border-box;
  padding: 4px 10px 0px;
  border-top: solid 1px #e8eaef;
}
.data-panel {
  box-sizing: border-box;
  padding: 5px;
}

/deep/.el-collapse-item__header {
  background-color: #f4f6f9;
  height: 28px;
  color: #000000;
  font-weight: bold;
}
.pagination-panel {
  text-align: right;
  padding: 5px;
  box-sizing: border-box;
}

/deep/ .el-dialog__title {
  font-size: 16px;
}

/deep/ .el-dialog__footer {
  padding-top: 20px;
}
</style>

<style>
.addForm .el-form-item__content {
  margin-left: 25px !important;
}
</style>
